<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>人脸和车牌信息遮拦处理</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            line-height: 1.6;
        }
        h1 {
            color: #333;
            text-align: center;
        }
        .upload-container {
            border: 2px dashed #ccc;
            padding: 30px;
            text-align: center;
            border-radius: 5px;
            margin-bottom: 20px;
            background-color: #f9f9f9;
        }
        .upload-container:hover {
            border-color: #aaa;
        }
        #file-input {
            display: none;
        }
        .upload-btn {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }
        .upload-btn:hover {
            background-color: #45a049;
        }
        #file-name {
            margin-top: 10px;
            font-size: 14px;
            color: #666;
        }
        #submit-btn {
            background-color: #008CBA;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            display: none;
        }
        #submit-btn:hover {
            background-color: #007B9E;
        }
        .result {
            margin-top: 20px;
            padding: 15px;
            border-radius: 4px;
            display: none;
        }
        .success {
            background-color: #dff0d8;
            color: #3c763d;
        }
        .error {
            background-color: #f2dede;
            color: #a94442;
        }
        .loading {
            text-align: center;
            display: none;
            margin: 20px 0;
        }
        .spinner {
            border: 5px solid #f3f3f3;
            border-top: 5px solid #3498db;
            border-radius: 50%;
            width: 30px;
            height: 30px;
            animation: spin 1s linear infinite;
            margin: 0 auto;
        }
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
</head>
<body>
    <h1>人脸和车牌信息遮拦处理</h1>
    
    <div class="upload-container">
        <label for="file-input" class="upload-btn">选择文件</label>
        <input type="file" id="file-input" accept="image/*,video/*">
        <div id="file-name">未选择文件</div>
    </div>
    
    <button id="submit-btn">上传并处理</button>
    
    <div class="loading">
        <div class="spinner"></div>
        <p>文件处理中，请稍候...</p>
    </div>
    
    <div id="result" class="result"></div>
    
    <script>
        const fileInput = document.getElementById('file-input');
        const fileNameDisplay = document.getElementById('file-name');
        const submitBtn = document.getElementById('submit-btn');
        const resultDiv = document.getElementById('result');
        const loadingDiv = document.querySelector('.loading');
        
        fileInput.addEventListener('change', function(e) {
            if (this.files && this.files.length > 0) {
                fileNameDisplay.textContent = this.files[0].name;
                submitBtn.style.display = 'block';
                resultDiv.style.display = 'none';
            }
        });
        
        submitBtn.addEventListener('click', async function() {
            if (!fileInput.files || fileInput.files.length === 0) {
                showResult('请先选择文件', 'error');
                return;
            }
            
            const file = fileInput.files[0];
            const formData = new FormData();
            formData.append('file', file);
            
            // 显示加载指示器
            loadingDiv.style.display = 'block';
            submitBtn.disabled = true;
            
            try {
                const response = await fetch('/upload', {
                    method: 'POST',
                    body: formData
                });
                
                const data = await response.json();
                
                if (response.ok) {
                    const downloadUrl = data.download_url;
                    showResult(
                        `文件处理成功！<br><a href="${downloadUrl}" download>点击下载处理后的文件</a>`,
                        'success'
                    );
                } else {
                    showResult(`处理失败: ${data.detail}`, 'error');
                }
            } catch (error) {
                showResult(`上传失败: ${error.message}`, 'error');
            } finally {
                loadingDiv.style.display = 'none';
                submitBtn.disabled = false;
            }
        });
        
        function showResult(message, type) {
            resultDiv.innerHTML = message;
            resultDiv.className = `result ${type}`;
            resultDiv.style.display = 'block';
        }
    </script>
</body>
</html>